package com.mind.adjust.controller;

import java.net.URLEncoder;
import java.util.List;
import java.io.IOException;

import com.mind.common.core.domain.model.LoginUser;
import com.mind.common.utils.SecurityUtils;
import jakarta.servlet.http.HttpServletResponse;

import com.mind.common.utils.poi.ExcelUtil;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.web.page.TableDataInfo;
import com.mind.common.log.annotation.Log;
import com.mind.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mind.system.domain.AjReviewConfig;
import com.mind.adjust.service.IAjReviewConfigService;
import org.springframework.web.multipart.MultipartFile;

/**
 * 智审配置Controller
 *
 * @author today
 * @date 2024-09-03
 */
@RestController
@RequestMapping("adjust/config")
public class AjReviewConfigController extends BaseController
{
    @Autowired
    private IAjReviewConfigService ajReviewConfigService;

    /**
     * 查询智审配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    //@ApiOperation(value = "查询智审配置列表")
    @GetMapping("/list")
    public TableDataInfo list(AjReviewConfig ajReviewConfig)
    {
        startPage();
        List<AjReviewConfig> list = ajReviewConfigService.selectAjReviewConfigList(ajReviewConfig);
        return getDataTable(list);
    }

    @Log(title = "智审配置", businessType = BusinessType.IMPORT)
    //@ApiOperation(value = "智审配置导入")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<AjReviewConfig> util = new ExcelUtil<AjReviewConfig>(AjReviewConfig.class);
        List<AjReviewConfig> configList = util.importExcel(file.getInputStream());
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String operName = "";
        if(loginUser != null){
            operName = loginUser.getUsername();
        }
        String message = ajReviewConfigService.importData(configList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    //@ApiOperation(value = "智审配置模板下载")
    @GetMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)throws IOException {
        ExcelUtil<AjReviewConfig> util = new ExcelUtil<AjReviewConfig>(AjReviewConfig.class);
        String fileName =  URLEncoder.encode("智审配置模板", "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
        util.importTemplateExcel(response, "智审配置数据");
    }

    /**
     * 导出智审配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    //@ApiOperation(value = "导出智审配置列表")
    @Log(title = "智审配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AjReviewConfig ajReviewConfig)
    {
        List<AjReviewConfig> list = ajReviewConfigService.selectAjReviewConfigList(ajReviewConfig);
        ExcelUtil<AjReviewConfig> util = new ExcelUtil<AjReviewConfig>(AjReviewConfig.class);
        util.exportExcel(response, list, "智审配置数据");
    }

    /**
     * 获取智审配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    //@ApiOperation(value = "获取智审配置详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ajReviewConfigService.selectAjReviewConfigById(id));
    }

    /**
     * 新增智审配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    //@ApiOperation(value = "新增智审配置")
    @Log(title = "智审配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AjReviewConfig ajReviewConfig)
    {
        return toAjax(ajReviewConfigService.insertAjReviewConfig(ajReviewConfig));
    }

    /**
     * 修改智审配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    //@ApiOperation(value = "修改智审配置")
    @Log(title = "智审配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AjReviewConfig ajReviewConfig)
    {
        return toAjax(ajReviewConfigService.updateAjReviewConfig(ajReviewConfig));
    }

    /**
     * 删除智审配置
     */
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    //@ApiOperation(value = "删除智审配置")
    @Log(title = "智审配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ajReviewConfigService.deleteAjReviewConfigByIds(ids));
    }
}
